<template>
	<view class="list">
		<!-- 背景毛玻璃色 -->
		<view class="fixbg" :style="{'background-image' : `url(${songList.coverImgUrl})`}"></view>
		<!-- 图标和顶部文字区 -->
		<MusicHead title='歌单' :icon='true' color='white'></MusicHead>
		
		<view class="container" v-show="isLoading">
			<scroll-view scroll-y="true" >
				<!-- 头部区域 -->
				<view class="list-head">
					<view class="list-head-img">
						<image :src="songList.coverImgUrl" mode=""></image>
						<text class="iconfont icon-yousanjiao">{{ songList.playCount | formatCount }}</text>
					</view>
					<view class="list-head-text">
						<view>{{songList.name}}</view>
						<view>
							<image :src="songList.creator.avatarUrl" mode=""></image>
							{{songList.creator.nickname}}
						</view>
						<view>
							{{songList.description}}
						</view>
					</view>
				</view>
				<!-- 分享给微信好友按钮，用了uniapp的APIbutton -->
				<button open-type="share" class="list-share">
					<text class="iconfont icon-fenxiang"></text>
					分享给微信好友
				</button>
				<!-- 歌曲列表 -->
				<view class="list-music">
					<view class="list-music-head">
						<text class="iconfont icon-bofang"></text>
						<text>播放全部</text>
						<text>(共{{ songList.trackCount }}首)</text>
					</view>
					<view class="list-music-item" v-for="(i,index) in songList.tracks" :key='index' @tap="handleToDetail(i.id)">
						<view class="list-music-top">
							{{index+1}}
						</view>
						<view class="list-music-song">
							<!-- 歌名 -->
							<view>{{i.name}}</view>
							<!-- 作者 -->
							<view>
								<image v-if="privileges[index].flag>60 && privileges[index].flag<70" src="../../static/dujia.png"></image>
								<image v-if="privileges[index].maxbr===999000" src="../../static/sq.png"></image>
								{{i.ar[0].name}} - {{i.al.name}}
							</view>
						</view>
						<text class="iconfont icon-bofang1"></text>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import MusicHead from '../../components/musichead/MusicHead.vue';
	import '@/common/iconfont.css';
	import {getSongList} from '../../common/api.js'
	
	export default {
		components:{
			MusicHead
		},
		data() {
			return {
				songList:{
					// 如果不预先定义一下就会出现undefined的报错，当然不会影响程序，但是看着不舒服
					// [渲染层网络层错误] Failed to load local image resource /pages/list/undefined the server responded with a status of 500
					coverImgUrl:''
				},
				privileges:[],
				isLoading:false
			}
		},
		onLoad(options) { // option为object类型，会序列化上个页面传递的参数
			getSongList(options.listId).then((res)=>{
				if(res[1].data.code==200){
					this.songList=res[1].data.playlist;
					this.privileges=res[1].data.privileges;
					this.$store.commit('INIT_TOPLISTIDS',this.songList.trackIds);
					this.isLoading=true;
				}
			})
		},
		methods: {
			handleToDetail(id){
				uni.navigateTo({
					url:`../detail/detail?id=${id}`
				})
			}
		}
	}
</script>

<style scoped>
	.list-head{
		display: flex;
		margin: 30rpx;
	}
	.list-head-img{
		width: 264rpx;
		height: 264rpx;
		border-radius: 30rpx;
		overflow: hidden;
		position: relative;
		margin-right: 42rpx;
	}
	.list-head-img image{
		width: 100%;
		height: 100%;
	}
	.list-head-img text{
		position: absolute;
		right: 8rpx;
		top: 8rpx;
		color: white;
		font-size: 26rpx;
	}
	.list-head-text{
		flex: 1;
		color: #f0f2f7;
	}
	.list-head-text view:nth-child(1){
		color: white;
		font-size: 34rpx;
	}
	.list-head-text view:nth-child(2){
		display: flex;
		margin: 20rpx 0;
		font-size: 24rpx;
		align-items: center;
	}
	.list-head-text view:nth-child(2) image{
		width: 54rpx;
		height: 54rpx;
		border-radius: 50%;
		margin-right: 14rpx;
	}
	.list-head-text view:nth-child(3){
		font-size: 22rpx;
		line-height: 34rpx;
		color: #EAEAEA;
	}
	.list-share{
		width: 330rpx;
		height: 74rpx;
		/* 让块级元素居中 */
		margin: 0 auto;
		background: rgba(0,0,0,0.4);
		border-radius: 36rpx;
		color: white;
		text-align: center;
		line-height: 74rpx;
		font-size: 28rpx;
	}
	.list-share text{
		margin-right: 16rpx;
	}
	.list-music{
		margin-top: 40rpx;
		border-radius: 50rpx;
		background: white;
		overflow: hidden;
	}
	.list-music-head{
		height: 50rpx;
		/* 注意到父元素.list-music的margintop有40rpx，传递给了子元素，解决方式：父元素加溢出隐藏 */
		margin: 30rpx 0 70rpx 24rpx;
	}
	.list-music-head text:nth-child(1){
		height: 50rpx;
		font-size: 50rpx;
	}
	.list-music-head text:nth-child(2){
		font-size: 30rpx;
		margin:0 10rpx 0 26rpx;
	}
	.list-music-head text:nth-child(3){
		font-size: 26rpx;
		color: #b2b2b2;
	}
	.list-music-item{display: flex;margin: 0 32rpx 66rpx 40rpx; align-items: center;color: #959595;}
	.list-music-top{width: 58rpx;font-size: 30rpx;line-height: 30rpx;}
	.list-music-song{
		flex: 1;
	}
	.list-music-song view:nth-child(1){font-size: 28rpx;color: black; width: 70vw;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
	.list-music-song view:nth-child(2){font-size: 20rpx;align-items: center;width: 70vw;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
	.list-music-song view:nth-child(2) image{
		width: 30rpx;
		height: 20rpx;
		margin-right: 10rpx;
	}
	.list-music-item text{font-size: 50rpx;color: #c7c7c7;}
</style>
